<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8"/>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
		<meta name="HandheldFriendly" content="true"/>
		<meta name="MobileOptimized" content="320"/>
		<title></title>
		<!--<link href="css/mui.min.css" rel="stylesheet"/>-->
    		<link rel="stylesheet" type="text/css" href="css/main.css"/>
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript">
var img = null;
var blist = [];
function scaned( t, r, f ) {
	var d = new Date();
	var h=d.getHours(),m=d.getMinutes(),s=d.getSeconds(),ms=d.getMilliseconds();
	if ( h < 10 ) { h='0'+h; }
	if ( m < 10 ) { m='0'+m; }
	if ( s < 10 ) { s='0'+s; }
	if ( ms < 10 ) { ms='00'+ms; } else if ( ms < 100 ) { ms='0'+ms; }
	var ts = '['+h+':'+m+':'+s+'.'+ms+']';
	var li=null,hl = document.getElementById("history");
	if ( blist.length > 0 ) {
		li = document.createElement("li");
		li.className = "ditem";
		hl.insertBefore( li, hl.childNodes[0] );
	} else {
		li = document.getElementById("nohistory");
	}
	li.id = blist.length;
	var html = '['+h+':'+m+':'+s+'.'+ms+']'+'　　'+t+'码<div class="hdata">';
	html += r;
	html += '</div>';
	li.innerHTML = html;
 	writeOffNo(r);
	li.setAttribute( "onclick", "selected(id);" );
	blist[blist.length] = {type:t,result:r,file:f};
	update( t, r, f );
}

function selected( id ) {
	var h = blist[id];
	update( h.type, h.result, h.file );
	if ( h.result.indexOf("http://")==0  || h.result.indexOf("https://")==0 ) {
		plus.nativeUI.confirm( h.result, function ( i ) {
			if ( i.index == 0 ) {
				plus.runtime.openURL( h.result );
			}
		}, "", ["打开","取消"] );
	} else {
		plus.nativeUI.alert( h.result );
	}
}
function update( t, r, f ) {
	outSet( "扫描成功：");
	outLine( t );
	outLine( r );
	outLine( "\n图片地址："+f );
	if ( !f || f=="null" ) {
		img.src = "../img/barcode.png";	
	} else {
		plus.io.resolveLocalFileSystemURL(f,function(entry){
			img.src=entry.toLocalURL();
		});
		//img.src = "http://localhost:13131/"+f;
	}
}
function onempty() {
	if ( window.plus ) {
		plus.nativeUI.alert('无扫描记录');
	} else {
		alert( '无扫描记录' );
	}
}
function cleanHistroy() {
	if ( blist.length > 0 ) {
		var hl = document.getElementById("history");
		hl.innerHTML = '<li id="nohistory" class="ditem" onclick="onempty();">无历史记录	</li>';
	}
	plus.io.resolveLocalFileSystemURL( "_doc/barcode/", function ( entry ) {
		entry.removeRecursively( function () {
			// Success
		}, function ( e ) {
			//alert( "failed"+e.message );
		});
	} );
}
		</script>
		<!--<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8"/>-->
		<style type="text/css" media="screen">
		</style>
	</head>
	<body onload="img=document.getElementById('bimg');">
		<div class="list_header">
			<h1 class="">核销</h1>
		</div>
		<div class="list_content">
			<div class="list_content_padded">
				<div class=" item_data">
					<h3 class="">扫描二维码直接查询</h1>
					<button id='login' class="list_button" onclick="clicked('http://admin.quleyuan.com.cn/respage/call/venderapp/barcode_scan.html',true,true);">点击扫描二维码</button>
				</div>
				<div class=" item_data">
					<h3 class="">手动输入核销码查询</h3>
					<div class="text_input">
						<input type="text" class="list_input writeOff_input" placeholder="请输入核销码">
						<button id='verification' class="list_button">验证</button>
					</div>
				</div>
			</div>
				<ul class="list_bottom_menu" >
					<li class="current">
						<a href="javascript:void(0);" id="writeOff">
							<div class="index_menu_btn">
								<span class="btn btn_4"><img src="images/writeOff_icon.png" class="img_1"/></span>
							</div>
							<div class="index_menu_text">核销</div>
						</a>
					</li>
					<li class="">
						<a href="add/order/sharecard.html">
							<div class="index_menu_btn">
								<span class="btn btn_5"><img src="images/sharecard_icon.png" class="img_1"/></span>
							</div>
							<div class="index_menu_text">乐享卡</div>
						</a>
					</li>
					<li class="">
						<a href="add/order/order.html">
							<div class="index_menu_btn">
								<span class="btn btn_5"><img src="images/order_icon.png" class="img_1"/></span>
							</div>
							<div class="index_menu_text">订单</div>
						</a>
					</li>
					<li class="">
						<a href="add/account.html" >
							<div class="index_menu_btn">
								<span class="btn btn_6"><img src="images/user_icon.png" class="img_1"/></span>
							</div>
							<div class="index_menu_text">账户</div>
						</a>
					</li>
				</ul>
				<div class="index_detail_show">
					<div class="list_content_padded">
						<div class=" item_data">
							<ul class="">
								<li class="">
										商家名称: <span class="vender_name">null</span>
								</li>
								<li class="">
										商品名称: <span class="goods_name">null</span>
								</li>
								<li class="">
										商品金额: <span class="goods_price">null</span>
								</li>
								<li class="">
										手&nbsp;&nbsp;机&nbsp;&nbsp;号: <span class="phone">null</span>
								</li>
								<li class="">
										订单时间: <span class="order_time">null</span>
								</li>
								<li class="">
										使用状态: <span class="is_use" class="">null</span>
								</li>
								<!--<li class="">
										支付金额: <span class="use_time">80元</span>
								</li>-->
							</ul>
						</div>
						<button id='off_back' class="list_button ">返回</button>
						<button id='confirm_use' class="list_button">确认使用</button>
					</div>
				</div>
</div>
		<div id="dcontent" class="dcontent" style="visibility: hidden; width:100%; overflow: hidden;" >
			<div class="button" onclick="clicked('app/barcode_scan.html',true,true);">扫一扫</div>
			<br/>
			<ul id="history" class="dlist" style="text-align:left;">
				<li id="nohistory" class="ditem" onclick="onempty();">无历史记录	</li>
			</ul>
			<br/>
			<div class="button button-waring" onclick="cleanHistroy();">清空历史记录</div>
		</div>
		
	</body>
	<script type="text/javascript" src="add/order/jquery-1.9.1.min.js" ></script>
	<script type="text/javascript" src="js/jquery.cookie.js" ></script>
	<script type="text/javascript" src="js/main.js" ></script>
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript" src="js/boxy.js" ></script>
	<script type="text/javascript" src="js/apiPath.js" ></script>
	<script type="text/javascript" charset="utf-8">
 //mui初始化
	
	$(function(){
		$("#verification").click(function(){
			 var r =$(".writeOff_input").val();
			if($(".writeOff_input").val() == "" || isNaN($(".writeOff_input").val())){
				boxy("请输入正确的核销码");
				$(".writeOff_input").focus();
			}else{
				writeOffNo(r);
			}
		});
		$("#off_back").click(function(){
			$(".index_detail_show").fadeOut();
		});
	});
	
	function writeOffNo(r){
			verify_code = r ; 
			$.ajax({
				url:"/ajax/call/vender_admin/verify_info",
				data:{
					"verify_sn":r
				},
				type:'post',
				success:function(data){
					if(data.errno){
						boxy("核销码不正确");
					}else{
						var res = data ;
						$(".index_detail_show").fadeIn();
						$(".vender_name").text(res.vender_name);
						$(".goods_name").text(res.goods_name);
						$(".goods_price").text(res.goods_price);
						$(".phone").text(res.phone);
						$(".order_time").text(res.order_time);
						if(res.left_count){
							$(".is_use").text(res.left_count);
						}else{
							if(res.is_use == 0 ){
								$(".is_use").addClass("no_used").text("未使用");
							}else if(res.is_use == 1 ){
								$(".is_use").text("已使用");
							}
						}
					}
				}
			});
		}
		
		var verify_code = null; 
		$("#confirm_use").click(function(){
			$.ajax({
				url:"/ajax/call/vender_admin/verify_use",
				data:{
					"verify_sn": verify_code
				},
				type:'post',
				success:function(data){
					if(data.errno){
						boxy("核销失败，稍后重试！");
						return;
					}else{
						var res = data ;
						$(".vender_name").text(res.vender_name);
						$(".goods_name").text(res.goods_name);
						$(".goods_price").text(res.goods_price);
						$(".phone").text(res.phone);
						$(".order_time").text(res.order_time);
						if(res.left_count){
							$(".is_use").text(res.left_count);
						}else{
							if(res.is_use == 0 ){
							$(".is_use").addClass("no_used").text("未使用");
							}else if(res.is_use == 1 ){
								$(".is_use").removeClass("no_used").text("已使用");
							}
						}
						
						boxy("核销成功^_^!");
						setTimeout(function(){
							$(".index_detail_show").fadeOut();
						},1500)
					}
				}
			});
		});
</script>
</html>
